<template>
  <div class="tool-website-traffic">
    <h2 class="bar-title mb-6 break-words">
      <span class="text-gray-1000 text-2xl font-semibold break-words w-full">{{$t('discord_disocrdMembers',{name: discordName})}}</span>
    </h2>
    <div class="flex items-stretch justify-around sm:justify-start flex-wrap gap-x-5 gap-y-4 border border-gray-2000 rounded-md px-4 sm:px-7 py-5">
      <div class="flex-shrink-0">
        <div class="text-lg text-gray-1000 text-center">{{$t('discord_lastMonthUser')}}</div>
        <div class="flex items-center justify-center mt-3">
          <span class="text-xl text-gray-1000 font-semibold mr-3">{{ hasRealVal(discord.user_num) ? $vReset(discord.user_num) : '--'}}</span>
          <svg-icon className="w-5 h-5"
            :isDiv="true"
            :iconName='hasRealVal(discord.month_diff) && discord.month_diff > 0 ? "up" : "down"'
            v-if="hasRealVal(discord.month_diff) && discord.month_diff!== 0"></svg-icon>
          <span class="text-xl font-semibold ml-1"
            :class="{'text-red-1000':hasRealVal(discord.month_diff) && discord.month_diff <0,'text-green-1100':hasRealVal(discord.month_diff) && discord.month_diff >0}"
            v-if="hasRealVal(discord.month_diff) && discord.month_diff!== 0">({{$vReset(discord.month_diff)}})</span>
        </div>
      </div>
    </div>

    <div class="mt-7"
      v-if="hasRealVal(totalMembersList) && totalMembersList.length > 0">
      <div class="chart-bar">
        <div class="text-xl text-gray-1000 font-semibold">{{$t('discord_totalMembers')}}</div>
        <no-ssr>
          <line-chart :chartData="totalMembersList"
            dId="totalVisitors"></line-chart>
        </no-ssr>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'DiscordTraffic',
  props: {
    discord: {
      type: Object | null,
      default() {
        return {}
      },
    },
    discordName: {
      type: String,
      default: '',
    },
  },
  watch: {
    discord: {
      handler: function (val) {
        if (val) {
          this.totalMembersList = this.discord.tool_discord_data
        }
      },
      immediate: true,
      deep: true,
    },
  },
  data() {
    return {
      totalMembersList: [],
    }
  },
}
</script>
<style lang='scss' scoped>
.tool-website-traffic {
  svg {
    color: rgba(0, 0, 0, 0) !important;
  }
}
</style>